<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="录入人员" v-if="judgeShow('creator')">
				<u-input v-model="infoObj.creator" placeholder="请输入录入人员" disabled></u-input>
			</u-form-item>
			<u-form-item label="录入日期" v-if="judgeShow('createDate')">
				<u-input v-model="infoObj.createDate" placeholder="请输入录入日期" disabled></u-input>
			</u-form-item>
			<u-form-item label="单号" v-if="judgeShow('taskId')">
				<u-input v-model="infoObj.taskId" placeholder="请输入单号期" disabled></u-input>
			</u-form-item>
			<u-form-item label="报价单别" v-if="judgeShow('ta001')">
				<u-input v-model="infoObj.ta001" placeholder="请输入报价单别" disabled></u-input>
			</u-form-item>
			<u-form-item label="报价单号" v-if="judgeShow('ta002')">
				<u-input v-model="infoObj.ta002" placeholder="请输入报价单号" disabled></u-input>
			</u-form-item>
			<u-form-item label="报价日期" v-if="judgeShow('ta003')">
				<u-input v-model="infoObj.ta003" placeholder="请输入报价日期" disabled></u-input>
			</u-form-item>
			<u-form-item label="币种" v-if="judgeShow('ta007')">
				<u-input v-model="infoObj.ta007" placeholder="请输入币种" disabled></u-input>
			</u-form-item>
			<u-form-item label="客户" v-if="judgeShow('ta004')">
				<u-input v-model="infoObj.ta004" placeholder="请输入客户" disabled></u-input>
			</u-form-item>
			<u-form-item label="业务人员" v-if="judgeShow('ta005')">
				<u-input v-model="infoObj.ta005" placeholder="请输入业务人员" disabled></u-input>
			</u-form-item>
			<u-form-item label="税种" v-if="judgeShow('ta022')">
				<u-input v-model="infoObj.ta022" placeholder="请输入税种" disabled></u-input>
			</u-form-item>
			<u-form-item label="汇率" v-if="judgeShow('ta008')">
				<u-input v-model="infoObj.ta008" placeholder="请输入汇率" disabled></u-input>
			</u-form-item>
			<u-form-item label="付款条件" v-if="judgeShow('ta026')">
				<u-input v-model="infoObj.ta026" placeholder="请输入付款条件" disabled></u-input>
			</u-form-item>
			<u-form-item label="计价方式" v-if="judgeShow('ta012')">
				<u-input v-model="infoObj.ta012" placeholder="请输入计价方式" disabled></u-input>
			</u-form-item>
			<u-form-item label="税率" v-if="judgeShow('ta024')">
				<u-input v-model="infoObj.ta024" placeholder="请输入税率" disabled></u-input>
			</u-form-item>
			<u-form-item label="价格说明" v-if="judgeShow('ta010')">
				<u-input v-model="infoObj.ta010" type="textarea" placeholder="请输入价格说明" disabled></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in lst" :key="i">
					<u-form-item label="序号" >
						{{i+1}}
					</u-form-item>
					 
					<u-form-item label="品号" v-if="judgeShow('tb004')">
						<u-input v-model="item.tb004" placeholder="品号" disabled></u-input>
					</u-form-item>
					<u-form-item label="品名" v-if="judgeShow('tb005')">
						<u-input v-model="item.tb005" placeholder="品名" disabled></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('tb006')">
						<u-input v-model="item.tb006" placeholder="规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="数量" v-if="judgeShow('tb007')">
						<u-input v-model="item.tb007" placeholder="数量" disabled></u-input>
					</u-form-item>
					<u-form-item label="模具分摊数量" labelWidth='200' v-if="judgeShow('udf53')">
						<u-input v-model="item.udf53" placeholder="模具分摊数量" disabled></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('tb008')">
						<u-input v-model="item.tb008" placeholder="单位" disabled></u-input>
					</u-form-item>
					 
					<u-form-item label="单价" v-if="judgeShow('tb009')">
						<u-input v-model="item.tb009" placeholder="单价" disabled></u-input>
					</u-form-item>
					<u-form-item label="税率" v-if="judgeShow('tb026')">
						<u-input v-model="item.tb026" placeholder="税率" disabled></u-input>
					</u-form-item>
					<u-form-item label="折扣率"  v-if="judgeShow('tb025')">
						<u-input v-model="item.tb025" placeholder="折扣率" disabled></u-input>
					</u-form-item>
					<u-form-item label="生效日" v-if="judgeShow('tb016')">
						<u-input v-model="item.tb016" placeholder="生效日" disabled></u-input>
					</u-form-item>
					<u-form-item label="失效日" v-if="judgeShow('tb017')">
						<u-input v-model="item.tb017" placeholder="失效日" disabled></u-input>
					</u-form-item>
					<u-form-item label="分量计价" v-if="judgeShow('tb013')">
						<u-input v-model="item.tb013" placeholder="分量计价" disabled></u-input>
					</u-form-item>
					<u-form-item label="数量以上" v-if="judgeShow('udf03')">
						<u-input v-model="item.udf03" placeholder="数量以上" disabled></u-input>
					</u-form-item>
					<u-form-item label="分量单价" v-if="judgeShow('udf04')">
						<u-input v-model="item.udf04" placeholder="分量单价" disabled></u-input>
					</u-form-item>
					<u-form-item label="分量折扣率" v-if="judgeShow('udf05')">
						<u-input v-model="item.udf05" placeholder="分量折扣率" disabled></u-input>
					</u-form-item>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getCoptaInfo
	} from '@/api/workFlow/flowEngine'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		data() {
			return {
				buyName: '',
				buyNameTwo: '',
				categoriesOfTaxesName: '',
				categoriesOfTaxesLst: [],
				tel: '', //联系人
				telTwo: '', //联系人
				hide: false,
				billEnCode: 'OrderNumber',
				dataForm: {},
				infoObj: {},
				lst: [],
				dictionaryInfo: {},
				info: {},
				formConf: {},
				listInfo: {
					optionOne: '',
					optionTwo: '',
					optionThree: '',
					optionFour: '',
					JoinStr: '',
					gochang: '',
				},
				id: '',
			}
		},
		methods: {
			init(data, id) {
				this.setting = data
				this.id = id
				this.getInfoFn(data)
			},
			getInfoFn(data) {
				getCoptaInfo(data).then(res => {
					if (res.code == 200) {
						this.lst = res.data.coptbList
						this.infoObj = res.data
						this.infoObj.taskId=res.data.taskId||'系统自动生成'
						if(this.lst.length>0){
							this.lst.forEach((item,index)=>{
								this.getTb002(item,index)
							})
						}
						this.getDictionaryDataSelectorFn()
						this.getDataInterfaceDataInfoMV002(this.infoObj.ta007)
						this.getDataInterfaceDataInfoMA003(this.infoObj.ta004)
						this.getDataInterfaceDataInfoMA004(this.infoObj.ta005)
						this.getDataInterfaceDataInfoMA005(this.infoObj.ta026)

					}
				})
			},
			getTb002(item,index){
					let data = {
						id:item.tb004,
						interfaceId: '362399109623061061',
						dblink: '',
						propsValue: 'MB001',
						relationField: 'MB001',
					}
					getDataInterfaceDataInfo('362399109623061061', data).then(res => {
						if (res.code == 200) {
							this.lst[index].tb005 = res.data.MB002
						}
					})
			},
			/**
			 * 查询税种列表
			 */
			getDictionaryDataSelectorFn() {
				getDictionaryDataSelector('411695330707391429').then(res => {
					if (res.code == 200) {
						res.data.list.forEach(res => {
							if (res.enCode == this.infoObj.ta022) {
								this.infoObj.ta022 = res.fullName
							}
						})
					}
				})
			},

			getDataInterfaceDataInfoMV002(id) {
				let data = {
					id,
					interfaceId: '362115609221143109',
					dblink: this.id,
					propsValue: 'MF001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362115609221143109', data).then(res => {
					if (res.code == 200) {
						this.infoObj.ta007 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMA003(id) {
				let data = {
					id,
					interfaceId: '362118781926906437',
					dblink: this.id,
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362118781926906437', data).then(res => {
					if (res.code == 200) {
						this.infoObj.ta004 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMA004(id) {
				let data = {
					id,
					interfaceId: '412024960106644997',
					dblink: this.id,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('412024960106644997', data).then(res => {
					if (res.code == 200) {
						this.infoObj.ta005 = res.data.JoinStr || ''

					}
				})
			},
			getDataInterfaceDataInfoMA005(id) {
				let data = {
					id,
					interfaceId: '381230997640850053',
					dblink: this.id,
					propsValue: 'NA002',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('381230997640850053', data).then(res => {
					if (res.code == 200) {
						this.infoObj.ta026 = res.data.JoinStr || ''
					}
				})
			},
			getDataInterfaceDataInfoJoinStr(id) {
				let data = {
					id,
					interfaceId: 362115953258928709,
					propsValue: 'NA002',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362115953258928709', data).then(res => {
					if (res.code == 200) {
						this.listInfo.JoinStr = res.data.JoinStr
					}
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>